#include <QCoreApplication>

#include "QHttpClient.h"

using namespace QtNet;

// 子结构体
struct Address
{
    QString city;
    QString street;
    int zipCode;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Address,city,street,zipCode)

// 父结构体（包含嵌套）
struct Person
{
    QString name;
    int age;
    Address address;  // 嵌套结构体
//    QDateTime time;
    QVector<QString> hobbies;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Person,name,address,hobbies)

// QMap<QString, QList<Person>>
void test_get_map_of_persons()
{
    QNetworkRequest request;
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    request.setUrl(QUrl("http://192.168.2.122:8081/jso"));

    QHttpClient::get(request, [](QMap<QString,QVector<QString>> v, QNetworkReply *reply) {

    });
}

// QList<Person>
void test_get_person_list()
{
    QNetworkRequest request;
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    request.setUrl(QUrl("http://192.168.2.122:8081/json"));

    QHttpClient::get(request, [](Person v, QNetworkReply *reply) {
        qDebug() << "1";
    });
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    test_get_map_of_persons();
    test_get_person_list();

    return a.exec();
}
